package com.ctshk.app.hotel.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.model.PageReq;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.utils.DateUtil;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.hotel.dto.h5.HotelDetailsDTO;
import com.ctshk.rpc.hotel.dto.h5.HotelHotsH5DTO;
import com.ctshk.rpc.hotel.dto.h5.HotelSearchDTO;
import com.ctshk.rpc.hotel.req.h5.HotelDetailsQueryH5Req;
import com.ctshk.rpc.hotel.req.h5.HotelQueryReq;
import com.ctshk.rpc.hotel.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @description 酒店-H5
 * @author 谢诗宏
 * @date 2021/5/6
 */
@RestController
@Api(value = "酒店管理", tags = "首页")
@RequestMapping("/h5")
public class H5HotelController extends BaseController {

    @DubboReference
    private IHotelH5Service hotelH5Service;

    @DubboReference
    private IHotelProductService hotelProductService;

    @DubboReference
    private INCNBHotelService ncnbHotelService;

    @ApiOperation(value="拉取龙腾捷旅酒店-(前端不调用此接口)", notes="拉取龙腾捷旅所有酒店信息-(前端不调用此接口)")
    @GetMapping("/init/api/ncnb")
    public Result initAPI() {
        return ncnbHotelService.initialize();
    }

    @ApiOperation(value="酒店搜索-h5/pc", notes="列表搜索-h5/pc")
    @PostMapping("/search")
    public Result<PageResponse<HotelSearchDTO>> queryList(@RequestBody @Valid HotelQueryReq req) {
        int days = DateUtil.daysBetween(req.getCheckInDate(), req.getCheckOutDate());
        if (days == 0) {
            return Result.failed(SystemError.HOTEL_10099);
        } else if (days > 28) {
            return Result.failed(SystemError.HOTEL_10100);
        }
        return Result.success(hotelH5Service.search(req));
    }

    @ApiOperation(value="热门酒店-h5", notes="酒店首页-热门酒店-H5")
    @PostMapping("/hot")
    public Result<PageResponse<HotelHotsH5DTO>> hot(@RequestBody @Valid PageReq req) {
        return Result.success(hotelH5Service.queryRecommendations2(req));
    }

    @ApiOperation(value="酒店详情-h5/pc", notes="酒店详情-h5/pc")
    @PostMapping("/detail")
    public Result<HotelDetailsDTO> details(@RequestBody @Valid HotelDetailsQueryH5Req req) {
        int days = DateUtil.daysBetween(req.getCheckInDate(), req.getCheckOutDate());
        if (days == 0) {
            return Result.failed(SystemError.HOTEL_10099);
        } else if (days > 28) {
            return Result.failed(SystemError.HOTEL_10100);
        }
        req.setUserId(getCurrentUserAllowNotLogInUserId());
        return hotelH5Service.detail(req);
    }

    @ApiOperation(value="酒店详情-h5/pc", notes="酒店详情-h5/pc")
    @PostMapping("/temp")
    public Result temp(@RequestBody @Valid HotelDetailsQueryH5Req req) {
        return hotelProductService.findHotelSalePriceInfoHandle(req.getPeopleNum(), req.getId(), req.getCheckInDate(), req.getCheckOutDate(),req.getRoomNum(), req.getUserId());
    }

}
